package com.dylan.springdatajpa.config;

import cn.hutool.core.util.IdUtil;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;

import java.io.Serializable;

/**
 * @author zhangshaojian
 * @description 雪花ID生成器
 * @date 2022/2/11 15:43
 */
public class SnowFlowId implements IdentifierGenerator {

    public static final String GENERATOR = "com.dylan.springdatajpa.config.SnowFlowId";

    @Override
    public Serializable generate(SharedSessionContractImplementor sharedSessionContractImplementor, Object o) throws HibernateException {
        return IdUtil.getSnowflake(0, 0).nextId();
    }
}